﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Higher_Lower
{
    public partial class _Default : System.Web.UI.Page
    {
        int currentCard;
        int nextCard;
        int score;
        protected void Page_Load(object sender, EventArgs e)
        {
            currentCard=randomCard();
        }

        protected void btnPlay_Click(object sender, EventArgs e)
        {

            nextCard = randomCard();


            if (RadioButtonList1.SelectedValue == "Higher")
            {
                if (nextCard > currentCard)
                {
                    score = score + 5;
                    lblScore.Text = score.ToString();
                }
                else
                {
                    score = score - 5;
                    lblScore.Text = score.ToString();
                }
            }

            else if (RadioButtonList1.SelectedValue == "Lower")
            {
                if (nextCard < currentCard)
                {
                    score = score + 5;
                    lblScore.Text = score.ToString();
                }
                else
                {
                    score = score - 5;
                    lblScore.Text = score.ToString();
                }
            }

                if (score < 0)
                {
                    lblScore.Text = "Game Over. Start Again!!";
                    btnPlay.Enabled = false;
                    btnRestart.Enabled = true;
                }

            currentCard = nextCard;
        }

        public int randomCard()
        {
            Random random = new Random();
            nextCard = random.Next(1, 13);
            Image1.ImageUrl = "~/Cards/c" + nextCard + ".png";
            return nextCard;
        }

        protected void btnRestart_Click(object sender, EventArgs e)
        {
            btnPlay.Enabled = true;
            lblScore.Text = "";
            currentCard = randomCard();
            btnRestart.Enabled = false;
        }
    }
}